//
//  CourseEvaluationSegmentVC.m
//  优学荟管理系统
//
//  Created by 星道 on 17/7/18.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "CourseEvaluationSegmentVC.h"
#import "CurriculumSignedVC.h"
#import "CurriculumAllEvaVC.h"
#import "HNThreeGoodEvaVC.h"

@interface CourseEvaluationSegmentVC ()
{
    // 白色的线
    IBOutlet UIView *_LineView;
    IBOutlet NSLayoutConstraint *_LineViewLeading;
    // 显示的视图
    IBOutlet UIView *_Content;

    UIButton *_TempButton;

    // 签到
    IBOutlet UIButton *_LeftButton;
    // 评价
    IBOutlet UIButton *_RightButton;
}
@property (nonatomic, strong) CurriculumSignedVC *CurriculumSignedVC;
@property (nonatomic, strong) CurriculumAllEvaVC *CurriculumAllEvaVC;
@end

@implementation CourseEvaluationSegmentVC

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"课程签到评价";

    [self CurriculumSigned:_LeftButton];
}

#pragma mark - 点击事件
/**
 课程签到
 */
- (IBAction)CurriculumSigned:(UIButton *)sender
{
    [self MgrCurriculumSigned:sender];
}

/**
 集体评价
 */
- (IBAction)CourseEvaluation:(UIButton *)sender
{
    [self MgrCurriculumAllEva:sender];
}

#pragma mark - 处理事件
/**
 处理课程签到
 */
- (void)MgrCurriculumSigned:(UIButton *)sender
{
    if (sender == _TempButton) return;
    // 靠左
    [UIView animateWithDuration:0.3 animations:^{
        _LineViewLeading.constant = 0;
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        //移除上一个子控制器
        [self.CurriculumAllEvaVC willMoveToParentViewController:nil];
        [self.CurriculumAllEvaVC removeFromParentViewController];
        [self.CurriculumAllEvaVC.view removeFromSuperview];
        // 增加子控制器
        [self addChildViewController:self.CurriculumSignedVC];
        // 增加子控制器的视图
        [_Content addSubview:self.CurriculumSignedVC.view];
        _TempButton = sender;
    }];
}


/**
 处理集体评价
 */
- (void)MgrCurriculumAllEva:(UIButton *)sender
{
    if (sender == _TempButton) return;
    // 靠右
    [UIView animateWithDuration:0.3 animations:^{
        _LineViewLeading.constant = SCREEN_WIDTH/2;
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        //移除上一个子控制器
        [self.CurriculumSignedVC willMoveToParentViewController:nil];
        [self.CurriculumSignedVC removeFromParentViewController];
        [self.CurriculumSignedVC.view removeFromSuperview];
        // 增加子控制器
        [self addChildViewController:self.CurriculumAllEvaVC];
        // 增加子控制器的视图
        [_Content addSubview:self.CurriculumAllEvaVC.view];
        _TempButton = sender;
    }];
}

#pragma mark - Setter
- (CurriculumSignedVC *)CurriculumSignedVC
{
    if (!_CurriculumSignedVC)
    {
        _CurriculumSignedVC = [[CurriculumSignedVC alloc] init];
        _CurriculumSignedVC.ID = self.ID;
        _CurriculumSignedVC.IsTeacher = YES;
        _CurriculumSignedVC.view.frame = CGRectMake(0, 0, _Content.frame.size.width, _Content.frame.size.height);
    }
    return _CurriculumSignedVC;
}

- (CurriculumAllEvaVC *)CurriculumAllEvaVC
{
    if (!_CurriculumAllEvaVC)
    {
        _CurriculumAllEvaVC = [[CurriculumAllEvaVC alloc] init];
        _CurriculumAllEvaVC.ID = self.ID;
        _CurriculumAllEvaVC.Name = self.Name;
        _CurriculumAllEvaVC.IsTeacher = YES;
        _CurriculumAllEvaVC.view.frame = CGRectMake(0, 0, _Content.frame.size.width, _Content.frame.size.height);
    }
    return _CurriculumAllEvaVC;
}
@end
